import {
  EquirectangularReflectionMapping,
  // PMREMGenerator,
  type Scene,
  type WebGLRenderer,
} from 'three'
import { RGBELoader } from 'three/examples/jsm/Addons.js'

export class Environment {
  scene: Scene
  renderer: WebGLRenderer
  // pmremGenerator?: PMREMGenerator
  constructor(scene: Scene, renderer: WebGLRenderer) {
    this.scene = scene
    this.renderer = renderer
    this.setup()
  }
  setup() {
    // this.pmremGenerator = new PMREMGenerator(this.renderer)
    // this.scene.environment = this.pmremGenerator.fromScene(new RoomEnvironment(), 1).texture
    this.loadHDR()
  }
  async loadHDR() {
    return new Promise(() => {
      const rgbeLoader = new RGBELoader()
      rgbeLoader.load('/hdri/docklands_01_1k.hdr', (hdrMap) => {
        hdrMap.mapping = EquirectangularReflectionMapping
        this.scene.environment = hdrMap
      })
    })
  }
}
